import { pinia, IUserState, PERSIST as persist, STORE } from '@/store'

const useUserStore = defineStore<string, IUserState>(
  STORE.USER,
  () => {
    const name = ref('超级管理员')
    const age = ref(0)
    const userInfo = computed(() => `${name.value}-${age.value}`)

    const changeUserName = (payload: string) => {
      name.value += payload
    }
    const changeAge = () => {
      age.value += 1
    }

    return {
      name,
      age,
      userInfo,
      changeUserName,
      changeAge,
    }
  },
  {
    persist,
  }
)

export const useUserStoreOutside = () => {
  return useUserStore(pinia)
}

export default useUserStore
